//
//  StoreData.swift
//  Example
//
//  Created by admin on 2020/9/1.
//  Copyright © 2020 admin. All rights reserved.
//

import Foundation
import RealmSwift

class StoreData: UGRealmData {
    
    @objc dynamic var name:String = "" //名字
    @objc dynamic var code:String = "" //代码

    
    public func inputPrice() -> String {
        let realm = try! Realm()
        let items =  realm.objects(StoreDataItem.self).filter("parment == '\(self.id)'")
        var pcount:Float = 0.0
        var amount:Float = 0.0
        for item in items {
            amount =  amount + (Float(item.ccount) ?? 0.0)
            pcount = (Float(item.ccount) ?? 0.0) * (Float(item.price) ?? 0.0)
        }
        if pcount == 0 {
            return "0.00"
        }
        let format = String(format:"%.3f",amount/pcount * 0.90)
        return format
    }
 
}

class StoreDataItem: UGRealmData {
    
    @objc dynamic var parment:String = "" //名字
    @objc dynamic var price:String = "0" //基准价
    @objc dynamic var ccount:String = "0" //基准价
}
